package thread;

//  线程的状态
public class demo13 {
    public static void main(String[] args) throws InterruptedException {
        Thread mainThread = Thread.currentThread();

/*        Thread t = new Thread(() -> {
        });

        //  New : 创建 Thread 对象, 但还没 start
        System.out.println(t.getState());

        t.start();
        t.join();

        //  TERMINATED : 操作系统内部的线程已经销毁了, 但是 Thread 对象还在, 线程的入口方法执行完毕
        System.out.println(t.getState());*/

        System.out.println("-----------------------");

/*        Thread t2 = new Thread(() -> {
            while (true) {
            }
        });

        t2.start();

        Thread.sleep(10);

        //  RUNNABLE : 正在运行状态
        System.out.println(t2.getState());*/

        System.out.println("-----------------------");

/*        Thread t3 = new Thread(() -> {
           while (true) {
               // WAITING : 死等 进入阻塞状态 join
               System.out.println(mainThread.getState());
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        });

        t3.start();

        t3.join();*/

        System.out.println("-----------------------");

        Thread t4 = new Thread(() -> {
            while (true) {
                // TIMED_WAITING : 带有超时时间的阻塞状态
                System.out.println(mainThread.getState());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        t4.start();

        t4.join(100);

    }
}
